//
//  SYDPersonalInfoViewController.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/8.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDPersonalInfoViewController.h"

@interface SYDPersonalInfoViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
@property (weak, nonatomic) IBOutlet UIImageView *userIcon;
@property (weak, nonatomic) IBOutlet UILabel *userNameLbl;
@property (weak, nonatomic) IBOutlet UILabel *userBirthLbl;
@property (weak, nonatomic) IBOutlet UILabel *userPhoneLbl;
@property (weak, nonatomic) IBOutlet UILabel *userCityLbl;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
@property(nonatomic,strong)SYDAccount *account;
@end

@implementation SYDPersonalInfoViewController
#pragma mark - 导航栏
- (void)navigationBarHandle{
    
    WEAKSELF
    [weakSelf backButtonAction:^{
        
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (iPhone8_X) {
        self.topConstraint.constant  = 88;
    } else {
        self.topConstraint.constant  = 64;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationBar.title = @"个人资料";
    [self navigationBarHandle];
    self.account = [SYDAccountTool getAccount];
    self.userNameLbl.text = self.account.username;
    self.userBirthLbl.text = self.account.birthday;
    self.userPhoneLbl.text = self.account.mobilephone;
    self.userCityLbl.text = self.account.cityName;
    self.userIcon.layer.cornerRadius = self.userIcon.width / 2;
    self.userIcon.layer.masksToBounds = YES;
    [self.userIcon drawBorderWithColor:WHITE_COLOR borderWidth:3];
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:self.account.headImageUrl] placeholderImage:[UIImage imageNamed:@"icon_head_portrait1"]];

    WEAKSELF
    self.userIcon.userInteractionEnabled = NO;
    [self.userIcon jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [SYDPhotoPickerManager shared].maxCount = 1;
        [[SYDPhotoPickerManager shared]showActionSheetInView:self.view fromController:self allowEdit:YES completion:^(UIImage *image) {
            weakSelf.userIcon.image = image;
            //上传图片
            [[SYDNetwork shareTool]uploadMultipartFilesWithParameters:nil mFile:@"mFile" uploadData:UIImageJPEGRepresentation(image, 0.5) success:^(NSURLSessionDataTask *task, id responseObject) {
                @try {
                    NSLog(@"responseObject:%@",responseObject);
                    if ([responseObject[@"statusCode"]integerValue] == 200) {
                        //                    weakSelf.IDPhotoFrontUrl = responseObject[@"obj"];
                    }
                } @catch (NSException *exception) {
                    NSLog(@"exception:%@",exception.description);
                } @finally {
                }
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                NSLog(@"error:%@",error);
            }];
        } cancelBlock:^{
            NSLog(@"cancel");
        }];
    }];
    
    [[self.phoneBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"13798235077"];
        UIWebView * callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [weakSelf.view addSubview:callWebview];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end





